package siebje.mobi.android;

import java.util.ArrayList;
import java.util.List;

import android.app.AlertDialog;
import android.app.TabActivity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TabHost;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.TextView;

public class ScoreTabs extends TabActivity implements View.OnClickListener,
		AdapterView.OnItemSelectedListener,
		CompoundButton.OnCheckedChangeListener {
	private List<List<Spinner>> spinners = new ArrayList<List<Spinner>>();
	private List<List<CheckBox>> seasons = new ArrayList<List<CheckBox>>();
	private List<CheckBox> mahjongg = new ArrayList<CheckBox>();
	private List<List<CheckBox>> concealed = new ArrayList<List<CheckBox>>();
	private List<List<TextView>> textviews = new ArrayList<List<TextView>>();
	private List<TextView> specialText = new ArrayList<TextView>();
	private TabHost mTabHost = null;

	private Player[] players = new Player[4];
	private int currentEastPlayer = 0;
	private int timesEast = 0;
	private Player.Wind prevailingWind = Player.Wind.EAST;
	private Bundle mahjonggSettings = null;
	private Dialog scoreDialog = null;

	public static final int SETTINGS_CALL = 241;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tabs);
		Resources res = getResources();

		Bundle extras = getIntent().getExtras();
		players[0] = new Player(extras.getString("player1"));
		players[1] = new Player(extras.getString("player2"));
		players[2] = new Player(extras.getString("player3"));
		players[3] = new Player(extras.getString("player4"));
		players[0].setScore(extras.getInt("score1"));
		players[1].setScore(extras.getInt("score2"));
		players[2].setScore(extras.getInt("score3"));
		players[3].setScore(extras.getInt("score4"));
		currentEastPlayer = extras.getInt("eastPlayer");
		timesEast = extras.getInt("timesEast");
		prevailingWind = (Player.Wind) extras.getSerializable("prevailingWind");
		this.setWinds(extras);

		// display game status
		scoreDialog = new Dialog(this);
		scoreDialog.setTitle("Score");
		View view = View.inflate(this, R.layout.scoredialog, null);
		((TextView) view.findViewById(R.id.DialogNextEastText))
				.setText(players[currentEastPlayer].getName()
						+ " will be East for the "
						+ nthNumberToString(timesEast + 1) + " time.");
		((TextView) view.findViewById(R.id.DialogNameText)).setText("  "
				+ players[0].getName() + "\n" + "  " + players[1].getName()
				+ "\n" + "  " + players[2].getName() + "\n" + "  "
				+ players[3].getName() + "\n");
		((TextView) view.findViewById(R.id.DialogScoreText)).setText(": "
				+ players[0].getScore() + "\n" + ": " + players[1].getScore()
				+ "\n" + ": " + players[2].getScore() + "\n" + ": "
				+ players[3].getScore() + "\n");
		((TextView) view.findViewById(R.id.DialogPrevailingText))
				.setText("Prevailing wind is " + prevailingWind);
		((ImageView) view.findViewById(R.id.DialogPrevailingImage))
				.setImageDrawable(res.getDrawable(getWindIcon(prevailingWind)));
		((Button) view.findViewById(R.id.DialogCloseButton))
				.setOnClickListener(new View.OnClickListener() {
					@Override
					public void onClick(View v) {
						scoreDialog.cancel();
					}
				});
		scoreDialog.setContentView(view);
		scoreDialog.show();

		((TextView) findViewById(R.id.P1Score)).setText("Score: "
				+ players[0].getScore());
		((TextView) findViewById(R.id.P2Score)).setText("Score: "
				+ players[1].getScore());
		((TextView) findViewById(R.id.P3Score)).setText("Score: "
				+ players[2].getScore());
		((TextView) findViewById(R.id.P4Score)).setText("Score: "
				+ players[3].getScore());

		getAllSpinners();
		getAllCheckBoxes();

		((Button) findViewById(R.id.RemiseButton)).setOnClickListener(this);
		((Button) findViewById(R.id.P1B)).setOnClickListener(this);
		((Button) findViewById(R.id.P2B)).setOnClickListener(this);
		((Button) findViewById(R.id.P3B)).setOnClickListener(this);
		((Button) findViewById(R.id.P4B)).setOnClickListener(this);
		((Button) findViewById(R.id.P1MahjonggButton))
				.setOnClickListener(this);
		((Button) findViewById(R.id.P2MahjonggButton))
				.setOnClickListener(this);
		((Button) findViewById(R.id.P3MahjonggButton))
				.setOnClickListener(this);
		((Button) findViewById(R.id.P4MahjonggButton))
				.setOnClickListener(this);

		mTabHost = getTabHost();

		mTabHost.addTab(mTabHost.newTabSpec(players[0].getName())
				.setIndicator(players[0].getName(), 
						res.getDrawable(getTabIcon(0)))
				.setContent(R.id.ScorePlayer1));
		mTabHost.addTab(mTabHost.newTabSpec(players[1].getName())
				.setIndicator(players[1].getName(), 
						res.getDrawable(getTabIcon(1)))
				.setContent(R.id.ScorePlayer2));
		mTabHost.addTab(mTabHost.newTabSpec(players[2].getName())
				.setIndicator(players[2].getName(), 
						res.getDrawable(getTabIcon(2)))
				.setContent(R.id.ScorePlayer3));
		mTabHost.addTab(mTabHost.newTabSpec(players[3].getName())
				.setIndicator(players[3].getName(), 
						res.getDrawable(getTabIcon(3)))
				.setContent(R.id.ScorePlayer4));

		mTabHost.setCurrentTab(0);
	}

	// Make sure the user doesn't accidentally quit the game
	@Override
	public void onBackPressed() {
		new AlertDialog.Builder(this).setMessage(
				"Are you sure you want to quit the current game?")
				.setCancelable(false).setPositiveButton("Yes",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int id) {
								ScoreTabs.super.onBackPressed();
							}
						}).setNegativeButton("No",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog, int id) {
								dialog.cancel();
							}
						}).show();
	}

	public void onClick(View v) {
		if (v.equals((Button) findViewById(R.id.P1B))
				|| v.equals((Button) findViewById(R.id.P2B))
				|| v.equals((Button) findViewById(R.id.P3B))
				|| v.equals((Button) findViewById(R.id.P4B))) {
			// Calculate scores
			int[] scores = new int[4];

			for (int k = 0; k < 4; k++) {
				int[] scoremult = getScore(k);
				scores[k] += scoremult[0];
				if (mahjongg.get(k).isChecked()) {
					int specialscore = 0;
					int additionalMult = 1;
					int additionalScore = 0;
					if (mahjonggSettings != null) {
						specialscore = mahjonggSettings.getInt("special");
						additionalMult = mahjonggSettings.getInt("multiplier");
						additionalScore = mahjonggSettings.getInt("score");
					}

					// if a special game is made, no regular multipliers apply
					if (specialscore == 0) {
						if (scores[k] == 0)
							scores[k] = 10;
						scores[k] += 20;
						scores[k] += additionalScore;
						scoremult[1] *= additionalMult;
						scores[k] *= scoremult[1];
					} else
						scores[k] = specialscore;
				} else {
					scores[k] *= scoremult[1];
				}
			}

			int[] calcScores = { 0, 0, 0, 0 };

			// accumulate scores
			// EAST has mahjongg
			if (mahjongg.get(currentEastPlayer).isChecked()) {
				calcScores[currentEastPlayer] = 6 * scores[currentEastPlayer];
				calcScores[(currentEastPlayer + 1) % 4] = 2
						* scores[(currentEastPlayer + 1) % 4]
						- scores[(currentEastPlayer + 2) % 4]
						- scores[(currentEastPlayer + 3) % 4] - 2
						* scores[currentEastPlayer];
				calcScores[(currentEastPlayer + 2) % 4] = 2
						* scores[(currentEastPlayer + 2) % 4]
						- scores[(currentEastPlayer + 3) % 4]
						- scores[(currentEastPlayer + 1) % 4] - 2
						* scores[currentEastPlayer];
				calcScores[(currentEastPlayer + 3) % 4] = 2
						* scores[(currentEastPlayer + 3) % 4]
						- scores[(currentEastPlayer + 1) % 4]
						- scores[(currentEastPlayer + 2) % 4] - 2
						* scores[currentEastPlayer];
				// next player will be mahjongg player only if
				// current player has been east for 4 times
				if (++timesEast > 3) {
					timesEast = 0;
					currentEastPlayer++;
				}
			}
			// NORTH has mahjongg
			else if (mahjongg.get((currentEastPlayer + 1) % 4).isChecked()) {
				calcScores[(currentEastPlayer + 1) % 4] = 4 * scores[(currentEastPlayer + 1) % 4];
				calcScores[(currentEastPlayer + 2) % 4] = 3
						* scores[(currentEastPlayer + 2) % 4]
						- scores[(currentEastPlayer + 3) % 4]
						- scores[(currentEastPlayer + 1) % 4] - 2
						* scores[currentEastPlayer];
				calcScores[(currentEastPlayer + 3) % 4] = 3
						* scores[(currentEastPlayer + 3) % 4]
						- scores[(currentEastPlayer + 1) % 4]
						- scores[(currentEastPlayer + 2) % 4] - 2
						* scores[currentEastPlayer];
				calcScores[currentEastPlayer] = 4 * scores[currentEastPlayer]
						- 2 * scores[(currentEastPlayer + 1) % 4] - 2
						* scores[(currentEastPlayer + 2) % 4] - 2
						* scores[(currentEastPlayer + 3) % 4];
				// next player will be east
				currentEastPlayer++;
				timesEast = 0;
			}
			// WEST has mahjongg
			else if (mahjongg.get((currentEastPlayer + 2) % 4).isChecked()) {
				calcScores[(currentEastPlayer + 2) % 4] = 4 * scores[(currentEastPlayer + 2) % 4];
				calcScores[(currentEastPlayer + 3) % 4] = 3
						* scores[(currentEastPlayer + 3) % 4]
						- scores[(currentEastPlayer + 1) % 4]
						- scores[(currentEastPlayer + 2) % 4] - 2
						* scores[currentEastPlayer];
				calcScores[currentEastPlayer] = 4 * scores[currentEastPlayer]
						- 2 * scores[(currentEastPlayer + 1) % 4] - 2
						* scores[(currentEastPlayer + 2) % 4] - 2
						* scores[(currentEastPlayer + 3) % 4];
				calcScores[(currentEastPlayer + 1) % 4] = 3
						* scores[(currentEastPlayer + 1) % 4]
						- scores[(currentEastPlayer + 2) % 4]
						- scores[(currentEastPlayer + 3) % 4] - 2
						* scores[currentEastPlayer];
				// next player will be east
				currentEastPlayer++;
				timesEast = 0;
			}
			// SOUTH has mahjongg
			else if (mahjongg.get((currentEastPlayer + 3) % 4).isChecked()) {
				calcScores[(currentEastPlayer + 3) % 4] = 4 * scores[(currentEastPlayer + 3) % 4];
				calcScores[currentEastPlayer] = 4 * scores[currentEastPlayer]
						- 2 * scores[(currentEastPlayer + 1) % 4] - 2
						* scores[(currentEastPlayer + 2) % 4] - 2
						* scores[(currentEastPlayer + 3) % 4];
				calcScores[(currentEastPlayer + 1) % 4] = 3
						* scores[(currentEastPlayer + 1) % 4]
						- scores[(currentEastPlayer + 2) % 4]
						- scores[(currentEastPlayer + 3) % 4] - 2
						* scores[currentEastPlayer];
				calcScores[(currentEastPlayer + 2) % 4] = 3
						* scores[(currentEastPlayer + 2) % 4]
						- scores[(currentEastPlayer + 3) % 4]
						- scores[(currentEastPlayer + 1) % 4] - 2
						* scores[currentEastPlayer];
				// next player will be east
				currentEastPlayer++;
				timesEast = 0;
			} else {
				if (++timesEast > 3) {
					timesEast = 0;
					currentEastPlayer++;
				}
			}

			for (int k = 0; k < 4; k++)
				players[k].addScore(calcScores[k]);

			// start new scorefield
			Intent tabInterface = new Intent(this, ScoreTabs.class);
			tabInterface.putExtra("player1", players[0].getName()).putExtra(
					"player2", players[1].getName()).putExtra("player3",
					players[2].getName()).putExtra("player4",
					players[3].getName());
			tabInterface.putExtra("score1", players[0].getScore()).putExtra(
					"score2", players[1].getScore()).putExtra("score3",
					players[2].getScore()).putExtra("score4",
					players[3].getScore());
			if (currentEastPlayer > 3) {
				currentEastPlayer = 0;
				prevailingWind = nextPrevailingWind(prevailingWind);
			}
			tabInterface.putExtra("eastPlayer", currentEastPlayer);
			tabInterface.putExtra("timesEast", timesEast);
			tabInterface.putExtra("prevailingWind", prevailingWind);
			this.startActivity(tabInterface);
			this.finish();
		} else if (v.equals((Button) findViewById(R.id.RemiseButton))) {
			if (++timesEast > 3) {
				timesEast = 0;
				currentEastPlayer++;
			}
			// start new scorefield
			Intent tabInterface = new Intent(this, ScoreTabs.class);
			tabInterface.putExtra("player1", players[0].getName()).putExtra(
					"player2", players[1].getName()).putExtra("player3",
					players[2].getName()).putExtra("player4",
					players[3].getName());
			tabInterface.putExtra("score1", players[0].getScore()).putExtra(
					"score2", players[1].getScore()).putExtra("score3",
					players[2].getScore()).putExtra("score4",
					players[3].getScore());
			if (currentEastPlayer > 3) {
				currentEastPlayer = 0;
				prevailingWind = nextWind(prevailingWind);
			}
			tabInterface.putExtra("eastPlayer", currentEastPlayer);
			tabInterface.putExtra("timesEast", timesEast);
			tabInterface.putExtra("prevailingWind", prevailingWind);
			this.startActivity(tabInterface);
			this.finish();
		} else {
			Intent settings = new Intent(this, MahjonggSettings.class);
			settings.setAction(Intent.ACTION_PICK);
			if(mahjonggSettings != null)
				settings.putExtras(mahjonggSettings);
			this.startActivityForResult(settings, SETTINGS_CALL);
		}
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		if (requestCode == SETTINGS_CALL) {
			mahjonggSettings = data.getExtras();
			showOtherElements(mahjonggSettings.getInt("special") == 0);
		}
	}
	
	private void showOtherElements(boolean visible){
		int visibility = visible ? View.VISIBLE : View.GONE;
		int playerNumber = 0;
		for(int k = 0 ; k < 4 ; k++)
			if(mahjongg.get(k).isChecked())
				playerNumber = k;
		
		for(int k = 0 ; k < spinners.get(playerNumber).size() ; k++)
			spinners.get(playerNumber).get(k)
					.setVisibility(visibility);
		
		for(int k = 0 ; k < concealed.get(playerNumber).size() ; k++)
			concealed.get(playerNumber).get(k)
					.setVisibility(visibility);
		
		//seasons are arranged by number instead of playernumber
		//for ease of calculation elsewhere
		for(int k = 0 ; k < seasons.size() ; k++)
			seasons.get(k).get(playerNumber)
					.setVisibility(visibility);
		
		for(int k = 0 ; k < textviews.get(playerNumber).size(); k++)
			textviews.get(playerNumber).get(k)
					.setVisibility(visibility);
		
		//special game text should be invisible when the rest is visible and vv
		if(visible)
			specialText.get(playerNumber).setVisibility(View.GONE);
		else {
			//we have to replace all /n by <br> for the HTML formatting
			specialText.get(playerNumber).setText(Html.fromHtml(
					"<b>" +
					mahjonggSettings.getString("specialTitle") + 
					"</b>" + "<br><br>" + 
					mahjonggSettings.getString("specialText")
						.replace("\n", "<br>")));
			specialText.get(playerNumber).setVisibility(View.VISIBLE);
		}
	}
	
	private void resetAllVisibility(){
		for(int playerNumber = 0 ; playerNumber < 4 ; playerNumber++) {
			for(int k = 0 ; k < spinners.get(playerNumber).size() ; k++)
				spinners.get(playerNumber).get(k)
						.setVisibility(View.VISIBLE);
			
			for(int k = 0 ; k < concealed.get(playerNumber).size() ; k++)
				concealed.get(playerNumber).get(k)
						.setVisibility(View.VISIBLE);
			
			//seasons are arranged by number instead of playernumber
			//for ease of calculation elsewhere
			for(int k = 0 ; k < seasons.size() ; k++)
				seasons.get(k).get(playerNumber)
						.setVisibility(View.VISIBLE);
			
			for(int k = 0 ; k < textviews.get(playerNumber).size(); k++)
				textviews.get(playerNumber).get(k)
						.setVisibility(View.VISIBLE);
			
			specialText.get(playerNumber).setVisibility(View.GONE);
		}
	}

	public void onItemSelected(AdapterView<?> parent, View view, int position,
			long id) {
		int playerNumber = 0;
		int index = 0;
		for (List<Spinner> list : spinners) {
			int tempIndex = list.indexOf(parent);
			if (tempIndex >= 0) {
				playerNumber = spinners.indexOf(list);
				index = tempIndex;
				break;
			}
		}

		if (index % 3 == 0) {
			// nothing
			if (((TextView) view).getText().equals("None"))// position == 0)
			{
				spinners.get(playerNumber).get(index + 1).setVisibility(
						View.INVISIBLE);
				spinners.get(playerNumber).get(index + 2).setVisibility(
						View.INVISIBLE);
			}
			// Chow
			else if (((TextView) view).getText().equals("Chow"))// position ==
																// 1)
			{
				spinners.get(playerNumber).get(index + 1).setVisibility(
						View.VISIBLE);
				spinners.get(playerNumber).get(index + 2).setVisibility(
						View.INVISIBLE);
				ArrayAdapter<CharSequence> categoryAdapter = ArrayAdapter
						.createFromResource(this, R.array.categories_Chow,
								android.R.layout.simple_spinner_item);
				categoryAdapter
						.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
				spinners.get(playerNumber).get(index + 1).setAdapter(
						categoryAdapter);
			}
			// remainder
			else if (((TextView) view).getText().equals("Remainder"))// position
																		// == 5)
			{
				spinners.get(playerNumber).get(index + 1).setVisibility(
						View.VISIBLE);
				spinners.get(playerNumber).get(index + 2).setVisibility(
						View.INVISIBLE);
				concealed.get(playerNumber).get(index / 3).setEnabled(false);
				concealed.get(playerNumber).get(index / 3).setChecked(true);
				ArrayAdapter<CharSequence> categoryAdapter = ArrayAdapter
						.createFromResource(this, R.array.remainder,
								android.R.layout.simple_spinner_item);
				categoryAdapter
						.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
				spinners.get(playerNumber).get(index + 1).setAdapter(
						categoryAdapter);
				// disable all following spinners
				for (int k = index + 3; k < spinners.get(playerNumber).size(); k++) {
					spinners.get(playerNumber).get(k).setEnabled(false);
					concealed.get(playerNumber).get(k / 3).setEnabled(false);
				}
			}
			// others
			else {
				spinners.get(playerNumber).get(index + 1).setVisibility(
						View.VISIBLE);
				spinners.get(playerNumber).get(index + 2).setVisibility(
						View.VISIBLE);
				for (int k = 0; k < spinners.get(playerNumber).size(); k++) {
					spinners.get(playerNumber).get(k).setEnabled(true);
					concealed.get(playerNumber).get(k / 3).setEnabled(true);
				}
				ArrayAdapter<CharSequence> categoryAdapter = ArrayAdapter
						.createFromResource(this, R.array.categories,
								android.R.layout.simple_spinner_item);
				categoryAdapter
						.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
				spinners.get(playerNumber).get(index + 1).setAdapter(
						categoryAdapter);
			}
		}

		if (index % 3 == 1) {
			ArrayAdapter<CharSequence> valueAdapter = null;
			switch (position) {
			case 0:
			case 1:
			case 2:
				valueAdapter = ArrayAdapter.createFromResource(this,
						R.array.numbers, android.R.layout.simple_spinner_item);
				valueAdapter
						.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
				spinners.get(playerNumber).get(index + 1).setAdapter(
						valueAdapter);
				break;
			case 3:
				valueAdapter = ArrayAdapter.createFromResource(this,
						R.array.winds, android.R.layout.simple_spinner_item);
				valueAdapter
						.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
				spinners.get(playerNumber).get(index + 1).setAdapter(
						valueAdapter);
				break;
			case 4:
				valueAdapter = ArrayAdapter.createFromResource(this,
						R.array.dragons, android.R.layout.simple_spinner_item);
				valueAdapter
						.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
				spinners.get(playerNumber).get(index + 1).setAdapter(
						valueAdapter);
				break;
			default:
				break;
			}
		}
	}

	public void onNothingSelected(AdapterView<?> parent) {
		// TODO Auto-generated method stub
	}

	// Make sure you cannot select the same season or Mahjongg for multiple
	// players
	public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
		if (mahjongg.contains(buttonView)) {
			if (isChecked) {
				((Button) findViewById(R.id.RemiseButton))
						.setVisibility(View.GONE);
				switch (mahjongg.indexOf(buttonView)) {
				case 0:
					((Button) findViewById(R.id.P1MahjonggButton))
							.setVisibility(View.VISIBLE);
					break;
				case 1:
					((Button) findViewById(R.id.P2MahjonggButton))
							.setVisibility(View.VISIBLE);
					break;
				case 2:
					((Button) findViewById(R.id.P3MahjonggButton))
							.setVisibility(View.VISIBLE);
					break;
				case 3:
					((Button) findViewById(R.id.P4MahjonggButton))
							.setVisibility(View.VISIBLE);
					break;
				}
				for (CheckBox c : mahjongg) {
					// non-mahjongg players
					if (c != (CheckBox) buttonView) {
						c.setEnabled(false);
					}
					// mahjongg player
					else {
						ArrayAdapter<CharSequence> categoryAdapter = ArrayAdapter
								.createFromResource(this,
										R.array.settypes_mahjongg,
										android.R.layout.simple_spinner_item);
						categoryAdapter
								.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
						for (int k = 0; k < spinners.get(mahjongg.indexOf(c))
								.size(); k += 3)
							spinners.get(mahjongg.indexOf(c)).get(k)
									.setAdapter(categoryAdapter);
					}
				}
			} else {
				//Mahjongg was unchecked so reset everything
				((Button) findViewById(R.id.RemiseButton))
						.setVisibility(View.VISIBLE);
				((Button) findViewById(R.id.P1MahjonggButton))
						.setVisibility(View.INVISIBLE);
				((Button) findViewById(R.id.P2MahjonggButton))
						.setVisibility(View.INVISIBLE);
				((Button) findViewById(R.id.P3MahjonggButton))
						.setVisibility(View.INVISIBLE);
				((Button) findViewById(R.id.P4MahjonggButton))
						.setVisibility(View.INVISIBLE);
				resetAllVisibility();
				mahjonggSettings = null;
				for (CheckBox c : mahjongg) {
					c.setEnabled(true);
					ArrayAdapter<CharSequence> categoryAdapter = ArrayAdapter
							.createFromResource(this, R.array.settypes,
									android.R.layout.simple_spinner_item);
					categoryAdapter
							.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
					for (int k = 0; k < spinners.get(mahjongg.indexOf(c))
							.size(); k += 3)
						spinners.get(mahjongg.indexOf(c)).get(k).setAdapter(
								categoryAdapter);
				}
			}
		} else {
			int index = 0;
			int subindex = 0;
			List<CheckBox> list = null;

			// find the appropriate box
			for (List<CheckBox> l : seasons) {
				if (l.contains(buttonView)) {
					index = seasons.indexOf(l);
					subindex = l.indexOf(buttonView);
					list = l;
					break;
				}
			}

			if (isChecked) {
				for (CheckBox c : seasons.get(index)) {
					if (list.indexOf(c) != subindex) {
						c.setEnabled(false);
					}
				}
			} else {
				for (CheckBox c : seasons.get(index)) {
					c.setEnabled(true);
				}
			}
		}
	}

	// put all the references to the spinners in a map
	private void getAllSpinners() {
		// Player 1
		List<Spinner> temp = new ArrayList<Spinner>();
		temp.add((Spinner) findViewById(R.id.P1R1S1));
		temp.add((Spinner) findViewById(R.id.P1R1S2));
		temp.add((Spinner) findViewById(R.id.P1R1S3));
		temp.add((Spinner) findViewById(R.id.P1R2S1));
		temp.add((Spinner) findViewById(R.id.P1R2S2));
		temp.add((Spinner) findViewById(R.id.P1R2S3));
		temp.add((Spinner) findViewById(R.id.P1R3S1));
		temp.add((Spinner) findViewById(R.id.P1R3S2));
		temp.add((Spinner) findViewById(R.id.P1R3S3));
		temp.add((Spinner) findViewById(R.id.P1R4S1));
		temp.add((Spinner) findViewById(R.id.P1R4S2));
		temp.add((Spinner) findViewById(R.id.P1R4S3));
		temp.add((Spinner) findViewById(R.id.P1R6S1));
		temp.add((Spinner) findViewById(R.id.P1R6S2));
		temp.add((Spinner) findViewById(R.id.P1R6S3));
		spinners.add(temp);

		// Player 2
		temp = new ArrayList<Spinner>();
		temp.add((Spinner) findViewById(R.id.P2R1S1));
		temp.add((Spinner) findViewById(R.id.P2R1S2));
		temp.add((Spinner) findViewById(R.id.P2R1S3));
		temp.add((Spinner) findViewById(R.id.P2R2S1));
		temp.add((Spinner) findViewById(R.id.P2R2S2));
		temp.add((Spinner) findViewById(R.id.P2R2S3));
		temp.add((Spinner) findViewById(R.id.P2R3S1));
		temp.add((Spinner) findViewById(R.id.P2R3S2));
		temp.add((Spinner) findViewById(R.id.P2R3S3));
		temp.add((Spinner) findViewById(R.id.P2R4S1));
		temp.add((Spinner) findViewById(R.id.P2R4S2));
		temp.add((Spinner) findViewById(R.id.P2R4S3));
		temp.add((Spinner) findViewById(R.id.P2R6S1));
		temp.add((Spinner) findViewById(R.id.P2R6S2));
		temp.add((Spinner) findViewById(R.id.P2R6S3));
		spinners.add(temp);

		// Player 3
		temp = new ArrayList<Spinner>();
		temp.add((Spinner) findViewById(R.id.P3R1S1));
		temp.add((Spinner) findViewById(R.id.P3R1S2));
		temp.add((Spinner) findViewById(R.id.P3R1S3));
		temp.add((Spinner) findViewById(R.id.P3R2S1));
		temp.add((Spinner) findViewById(R.id.P3R2S2));
		temp.add((Spinner) findViewById(R.id.P3R2S3));
		temp.add((Spinner) findViewById(R.id.P3R3S1));
		temp.add((Spinner) findViewById(R.id.P3R3S2));
		temp.add((Spinner) findViewById(R.id.P3R3S3));
		temp.add((Spinner) findViewById(R.id.P3R4S1));
		temp.add((Spinner) findViewById(R.id.P3R4S2));
		temp.add((Spinner) findViewById(R.id.P3R4S3));
		temp.add((Spinner) findViewById(R.id.P3R6S1));
		temp.add((Spinner) findViewById(R.id.P3R6S2));
		temp.add((Spinner) findViewById(R.id.P3R6S3));
		spinners.add(temp);

		// Player 4
		temp = new ArrayList<Spinner>();
		temp.add((Spinner) findViewById(R.id.P4R1S1));
		temp.add((Spinner) findViewById(R.id.P4R1S2));
		temp.add((Spinner) findViewById(R.id.P4R1S3));
		temp.add((Spinner) findViewById(R.id.P4R2S1));
		temp.add((Spinner) findViewById(R.id.P4R2S2));
		temp.add((Spinner) findViewById(R.id.P4R2S3));
		temp.add((Spinner) findViewById(R.id.P4R3S1));
		temp.add((Spinner) findViewById(R.id.P4R3S2));
		temp.add((Spinner) findViewById(R.id.P4R3S3));
		temp.add((Spinner) findViewById(R.id.P4R4S1));
		temp.add((Spinner) findViewById(R.id.P4R4S2));
		temp.add((Spinner) findViewById(R.id.P4R4S3));
		temp.add((Spinner) findViewById(R.id.P4R6S1));
		temp.add((Spinner) findViewById(R.id.P4R6S2));
		temp.add((Spinner) findViewById(R.id.P4R6S3));
		spinners.add(temp);

		ArrayAdapter<CharSequence> typeAdapter = ArrayAdapter
				.createFromResource(this, R.array.settypes,
						android.R.layout.simple_spinner_item);
		ArrayAdapter<CharSequence> categoryAdapter = ArrayAdapter
				.createFromResource(this, R.array.categories,
						android.R.layout.simple_spinner_item);
		ArrayAdapter<CharSequence> valueAdapter = ArrayAdapter
				.createFromResource(this, R.array.numbers,
						android.R.layout.simple_spinner_item);

		typeAdapter
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		categoryAdapter
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
		valueAdapter
				.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

		for (List<Spinner> list : spinners) {
			for (int k = 0; k < list.size(); k += 3) {
				list.get(k).setAdapter(typeAdapter);
				list.get(k).setOnItemSelectedListener(this);
				list.get(k + 1).setAdapter(categoryAdapter);
				list.get(k + 1).setOnItemSelectedListener(this);
				list.get(k + 2).setAdapter(valueAdapter);
				list.get(k + 2).setOnItemSelectedListener(this);
			}
		}
	}

	// put all the references to the checkboxes in a list
	private void getAllCheckBoxes() {
		for (int k = 0; k < 8; k++)
			seasons.add(new ArrayList<CheckBox>());

		// Player 1
		List<CheckBox> temp = new ArrayList<CheckBox>();
		temp.add((CheckBox) findViewById(R.id.P1R1C));
		temp.add((CheckBox) findViewById(R.id.P1R2C));
		temp.add((CheckBox) findViewById(R.id.P1R3C));
		temp.add((CheckBox) findViewById(R.id.P1R4C));
		temp.add((CheckBox) findViewById(R.id.P1R6C));
		concealed.add(temp);
		List<TextView> texts = new ArrayList<TextView>();
		texts.add((TextView) findViewById(R.id.P1R5T1));
		seasons.get(0).add((CheckBox) findViewById(R.id.P1R5C1));
		seasons.get(1).add((CheckBox) findViewById(R.id.P1R5C2));
		seasons.get(2).add((CheckBox) findViewById(R.id.P1R5C3));
		seasons.get(3).add((CheckBox) findViewById(R.id.P1R5C4));
		texts.add((TextView) findViewById(R.id.P1R5T2));
		seasons.get(4).add((CheckBox) findViewById(R.id.P1R5C5));
		seasons.get(5).add((CheckBox) findViewById(R.id.P1R5C6));
		seasons.get(6).add((CheckBox) findViewById(R.id.P1R5C7));
		seasons.get(7).add((CheckBox) findViewById(R.id.P1R5C8));
		textviews.add(texts);
		specialText.add((TextView) findViewById(R.id.P1Special));
		
		// Player 2
		temp = new ArrayList<CheckBox>();
		temp.add((CheckBox) findViewById(R.id.P2R1C));
		temp.add((CheckBox) findViewById(R.id.P2R2C));
		temp.add((CheckBox) findViewById(R.id.P2R3C));
		temp.add((CheckBox) findViewById(R.id.P2R4C));
		temp.add((CheckBox) findViewById(R.id.P2R6C));
		concealed.add(temp);
		texts = new ArrayList<TextView>();
		texts.add((TextView) findViewById(R.id.P2R5T1));
		seasons.get(0).add((CheckBox) findViewById(R.id.P2R5C1));
		seasons.get(1).add((CheckBox) findViewById(R.id.P2R5C2));
		seasons.get(2).add((CheckBox) findViewById(R.id.P2R5C3));
		seasons.get(3).add((CheckBox) findViewById(R.id.P2R5C4));
		texts.add((TextView) findViewById(R.id.P2R5T2));
		seasons.get(4).add((CheckBox) findViewById(R.id.P2R5C5));
		seasons.get(5).add((CheckBox) findViewById(R.id.P2R5C6));
		seasons.get(6).add((CheckBox) findViewById(R.id.P2R5C7));
		seasons.get(7).add((CheckBox) findViewById(R.id.P2R5C8));
		textviews.add(texts);
		specialText.add((TextView) findViewById(R.id.P2Special));

		// Player 3
		temp = new ArrayList<CheckBox>();
		temp.add((CheckBox) findViewById(R.id.P3R1C));
		temp.add((CheckBox) findViewById(R.id.P3R2C));
		temp.add((CheckBox) findViewById(R.id.P3R3C));
		temp.add((CheckBox) findViewById(R.id.P3R4C));
		temp.add((CheckBox) findViewById(R.id.P3R6C));
		concealed.add(temp);
		texts = new ArrayList<TextView>();
		texts.add((TextView) findViewById(R.id.P3R5T1));
		seasons.get(0).add((CheckBox) findViewById(R.id.P3R5C1));
		seasons.get(1).add((CheckBox) findViewById(R.id.P3R5C2));
		seasons.get(2).add((CheckBox) findViewById(R.id.P3R5C3));
		seasons.get(3).add((CheckBox) findViewById(R.id.P3R5C4));
		texts.add((TextView) findViewById(R.id.P3R5T2));
		seasons.get(4).add((CheckBox) findViewById(R.id.P3R5C5));
		seasons.get(5).add((CheckBox) findViewById(R.id.P3R5C6));
		seasons.get(6).add((CheckBox) findViewById(R.id.P3R5C7));
		seasons.get(7).add((CheckBox) findViewById(R.id.P3R5C8));
		textviews.add(texts);
		specialText.add((TextView) findViewById(R.id.P3Special));

		// Player 4
		temp = new ArrayList<CheckBox>();
		temp.add((CheckBox) findViewById(R.id.P4R1C));
		temp.add((CheckBox) findViewById(R.id.P4R2C));
		temp.add((CheckBox) findViewById(R.id.P4R3C));
		temp.add((CheckBox) findViewById(R.id.P4R4C));
		temp.add((CheckBox) findViewById(R.id.P4R6C));
		concealed.add(temp);
		texts = new ArrayList<TextView>();
		texts.add((TextView) findViewById(R.id.P4R5T1));
		seasons.get(0).add((CheckBox) findViewById(R.id.P4R5C1));
		seasons.get(1).add((CheckBox) findViewById(R.id.P4R5C2));
		seasons.get(2).add((CheckBox) findViewById(R.id.P4R5C3));
		seasons.get(3).add((CheckBox) findViewById(R.id.P4R5C4));
		texts.add((TextView) findViewById(R.id.P4R5T2));
		seasons.get(4).add((CheckBox) findViewById(R.id.P4R5C5));
		seasons.get(5).add((CheckBox) findViewById(R.id.P4R5C6));
		seasons.get(6).add((CheckBox) findViewById(R.id.P4R5C7));
		seasons.get(7).add((CheckBox) findViewById(R.id.P4R5C8));
		textviews.add(texts);
		specialText.add((TextView) findViewById(R.id.P4Special));

		// Mahjongg Checkboxes
		mahjongg.add((CheckBox) findViewById(R.id.P1Mahjongg));
		mahjongg.add((CheckBox) findViewById(R.id.P2Mahjongg));
		mahjongg.add((CheckBox) findViewById(R.id.P3Mahjongg));
		mahjongg.add((CheckBox) findViewById(R.id.P4Mahjongg));

		for (List<CheckBox> l : seasons) {
			for (CheckBox c : l) {
				c.setOnCheckedChangeListener(this);
			}
		}

		for (CheckBox c : mahjongg) {
			c.setOnCheckedChangeListener(this);
		}
	}

	private int[] getScore(int playerNumber) {
		int score = 0;
		int multiplier = 1;
		boolean noChows = true;
		boolean allConcealed = true;
		boolean clean = true;
		boolean oneColor = true;
		boolean onlyHonors = true;
		boolean onlyTerminals = true;
		boolean onlyMajor = true;
		boolean onlyMinor = true;
		Player player = players[playerNumber];
		String currentCat = null;
		String currentVal = null;

		for (int index = 0; index < 5; index++) {
			int tempScore = 0;
			String type = spinners.get(playerNumber).get((index * 3))
					.getSelectedItem().toString();
			String cat = spinners.get(playerNumber).get((index * 3) + 1)
					.getSelectedItem().toString();
			String val = spinners.get(playerNumber).get((index * 3) + 2)
					.getSelectedItem().toString();
			if (type.equals("Chow")) {
				if (currentCat == null)
					currentCat = cat;
				if (!cat.equals(currentCat))
					oneColor = false;
				if (!(cat.equals(currentCat) || cat.equals("Dragons") || cat
						.equals("Winds")))
					clean = false;
				onlyTerminals = false;
				onlyHonors = false;
				onlyMajor = false;
				onlyMinor = false;
				noChows = false;
				if (!concealed.get(playerNumber).get(index).isChecked())
					allConcealed = false;
			} else if (type.equals("Pung")) {
				if (currentCat == null)
					currentCat = cat;
				else if (currentCat.equals("Dragons")
						|| currentCat.equals("Winds"))
					currentCat = cat;
				if (!(currentCat.equals("Dragons") || currentCat
						.equals("Winds")))
					onlyHonors = false;
				if (!cat.equals(currentCat))
					oneColor = false;
				if (!(cat.equals(currentCat) || cat.equals("Dragons") || cat
						.equals("Winds")))
					clean = false;

				if (currentVal == null) {
					currentVal = val;
				}
				if (!((currentVal.equals("1") || currentVal.equals("9") || (currentCat
						.equals("Dragons") || currentCat.equals("Winds"))) && (val
						.equals("1") || val.equals("9")))) {
					if (!(currentCat.equals("Dragons") || currentCat
							.equals("Winds"))) {
						onlyMajor = false;
					} else {
						onlyMinor = false;
					}
					onlyTerminals = false;
				} else {
					if ((currentCat.equals("Dragons") || currentCat
							.equals("Winds")))
						onlyTerminals = false;
					onlyMinor = false;
				}

				tempScore = 2;
				if (cat.equals("Dragons")) {
					tempScore *= 2;
					multiplier *= 2;
				} else if (cat.equals("Winds")) {
					tempScore *= 2;
					if (player.getWind().equals(prevailingWind))
						multiplier *= 2;
					if (player.getWind().toString().equals(val))
						multiplier *= 2;
				} else if (val.equals("1") || val.equals("9")) {
					tempScore *= 2;
				}

				if (concealed.get(playerNumber).get(index).isChecked())
					tempScore *= 2;
				else
					allConcealed = false;
			} else if (type.equals("Kong")) {
				if (currentCat == null)
					currentCat = cat;
				else if (currentCat.equals("Dragons")
						|| currentCat.equals("Winds"))
					currentCat = cat;
				if (!(currentCat.equals("Dragons") || currentCat
						.equals("Winds")))
					onlyHonors = false;
				if (!cat.equals(currentCat))
					oneColor = false;
				if (!(cat.equals(currentCat) || cat.equals("Dragons") || cat
						.equals("Winds")))
					clean = false;

				if (currentVal == null) {
					currentVal = val;
				}
				if (!((currentVal.equals("1") || currentVal.equals("9") || (currentCat
						.equals("Dragons") || currentCat.equals("Winds"))) && (val
						.equals("1") || val.equals("9")))) {
					if (!(currentCat.equals("Dragons") || currentCat
							.equals("Winds"))) {
						onlyMajor = false;
					} else {
						onlyMinor = false;
					}
					onlyTerminals = false;
				} else {
					if ((currentCat.equals("Dragons") || currentCat
							.equals("Winds")))
						onlyTerminals = false;
					onlyMinor = false;
				}

				tempScore = 8;
				if (cat.equals("Dragons") || cat.equals("Winds"))
					tempScore *= 2;
				else if (val.equals("1") || val.equals("9"))
					tempScore *= 2;

				if (concealed.get(playerNumber).get(index).isChecked())
					tempScore *= 2;
				else
					allConcealed = false;
			} else if (type.equals("Pair")) {
				if (currentCat == null)
					currentCat = cat;
				else if (currentCat.equals("Dragons")
						|| currentCat.equals("Winds"))
					currentCat = cat;
				if (!(currentCat.equals("Dragons") || currentCat
						.equals("Winds")))
					onlyHonors = false;
				if (!cat.equals(currentCat))
					oneColor = false;
				if (!(cat.equals(currentCat) || cat.equals("Dragons") || cat
						.equals("Winds")))
					clean = false;

				if (currentVal == null) {
					currentVal = val;
				}
				if (!((currentVal.equals("1") || currentVal.equals("9") || (currentCat
						.equals("Dragons") || currentCat.equals("Winds"))) && (val
						.equals("1") || val.equals("9")))) {
					if (!(currentCat.equals("Dragons") || currentCat
							.equals("Winds"))) {
						onlyMajor = false;
					} else {
						onlyMinor = false;
					}
					onlyTerminals = false;
				} else {
					if ((currentCat.equals("Dragons") || currentCat
							.equals("Winds")))
						onlyTerminals = false;
					onlyMinor = false;
				}

				if (cat.equals("Dragons")) {
					tempScore += 2;
				} else if (cat.equals("Winds")) {
					if (player.getWind().equals(prevailingWind)) {
						tempScore += 2;
					}
					if (player.getWind().toString().equals(val)) {
						tempScore += 2;
					}
				}
				if (!concealed.get(playerNumber).get(index).isChecked()) {
					allConcealed = false;
				}
			} else if (type.equals("Remainder")) {
				// no mahjongg, so these are false by default
				allConcealed = false;
				noChows = false;
				// rest
				if (cat.equals("Nothing Special")) {
					clean = false;
					oneColor = false;
					onlyHonors = false;
					onlyTerminals = false;
					onlyMajor = false;
					onlyMinor = false;
				} else if (cat
						.equals("Single Color: 1's, 9's, Winds & Dragons")) {
					oneColor = false;
					onlyHonors = false;
					onlyMinor = false;
				} else if (cat.equals("Single Color: 1's & 9's")) {
					onlyHonors = false;
					onlyTerminals = false;
					onlyMinor = false;
				} else if (cat.equals("Single Color: Winds & Dragons")) {
					oneColor = false;
					onlyHonors = false;
					onlyTerminals = false;
					onlyMajor = false;
					onlyMinor = false;
				} else if (cat.equals("Single Color")) {
					onlyHonors = false;
					onlyTerminals = false;
					onlyMajor = false;
				} else if (cat.equals("1's, 9's, Winds & Dragons")) {
					clean = false;
					oneColor = false;
					onlyHonors = false;
					onlyTerminals = false;
					onlyMinor = false;
				} else if (cat.equals("1's & 9's")) {
					clean = false;
					oneColor = false;
					onlyHonors = false;
					onlyMinor = false;
				} else if (cat.equals("Winds & Dragons")) {
					oneColor = false;
					onlyTerminals = false;
					onlyMinor = false;
				}
			}
			score += tempScore;
		}

		// handle seasons
		boolean[] allSeasons = { false, false, false, false };
		boolean[] allFlowers = { false, false, false, false };
		int tempMult = 1;
		for (List<CheckBox> list : seasons) {
			CheckBox c = list.get(playerNumber);
			if (c.isChecked()) {
				score += 4;
				if (doesWindMatchSeason(seasons.indexOf(list), player.getWind()))
					tempMult *= 2;
				// if(doesWindMatchSeason(seasons.indexOf(list),
				// prevailingWind))
				// tempMult *= 2;
				switch (seasons.indexOf(list)) {
				case 0:
					allSeasons[0] = true;
					break;
				case 4:
					allFlowers[0] = true;
					break;
				case 1:
					allSeasons[1] = true;
					break;
				case 5:
					allFlowers[1] = true;
					break;
				case 2:
					allSeasons[2] = true;
					break;
				case 6:
					allFlowers[2] = true;
					break;
				case 3:
					allSeasons[3] = true;
					break;
				case 7:
					allFlowers[3] = true;
					break;
				}
			}
		}
		if (allSeasons[0] && allSeasons[1] && allSeasons[2] && allSeasons[3]) {
			multiplier *= 8;
		} else if (allFlowers[0] && allFlowers[1] && allFlowers[2]
				&& allFlowers[3]) {
			multiplier *= 8;
		} else {
			multiplier *= tempMult;
		}

		// apply multipliers
		if (oneColor || onlyHonors || onlyTerminals) {
			multiplier *= 8;
		} else if (clean) {
			multiplier *= 2;
		}
		// only terminals and honors
		else if (onlyMajor) {
			multiplier *= 2;
		}
		// unused
		else if (onlyMinor) {
			// multiplier *= 2;
		}

		// additional points for Mahjongg
		if (noChows && mahjongg.get(playerNumber).isChecked()) {
			score += 10;
		}
		if (allConcealed && mahjongg.get(playerNumber).isChecked()) {
			multiplier *= 2;
		}

		// display game status
		/*
		 * if(playerNumber == 0) { Dialog d = new Dialog(this);
		 * d.setTitle("Score"); TextView tv = new TextView(this); tv.setText(
		 * "Score: " + score + "\n" + "Multiplier: " + multiplier + "\n" +
		 * "One Color:\t\t\t" + oneColor + "\n" + "Only Honors:\t\t" +
		 * onlyHonors + "\n" + "Only Terminals:\t" + onlyTerminals + "\n" +
		 * "Clean:\t\t\t\t\t" + clean + "\n" + "Only Majors:\t\t" + onlyMajor +
		 * "\n" + "Only Minors:\t\t" + onlyMinor + "\n" + "No Chows:\t\t\t" +
		 * noChows + "\n" + "All Concealed:\t\t" + allConcealed);
		 * d.setContentView(tv); d.setCanceledOnTouchOutside(true); d.show(); }
		 */

		int[] scores = { score, multiplier };
		return scores;
	}

	private void setWinds(Bundle extras) {
		switch (extras.getInt("eastPlayer")) {
		case 0:
			players[0].setWind(Player.Wind.EAST);
			players[1].setWind(Player.Wind.NORTH);
			players[2].setWind(Player.Wind.WEST);
			players[3].setWind(Player.Wind.SOUTH);
			break;
		case 1:
			players[1].setWind(Player.Wind.EAST);
			players[2].setWind(Player.Wind.NORTH);
			players[3].setWind(Player.Wind.WEST);
			players[0].setWind(Player.Wind.SOUTH);
			break;
		case 2:
			players[2].setWind(Player.Wind.EAST);
			players[3].setWind(Player.Wind.NORTH);
			players[0].setWind(Player.Wind.WEST);
			players[1].setWind(Player.Wind.SOUTH);
			break;
		case 3:
			players[3].setWind(Player.Wind.EAST);
			players[0].setWind(Player.Wind.NORTH);
			players[1].setWind(Player.Wind.WEST);
			players[2].setWind(Player.Wind.SOUTH);
			break;
		default:
			break;
		}
	}

	private Player.Wind nextWind(Player.Wind wind) {
		switch (wind) {
		case EAST:
			return Player.Wind.SOUTH;
		case SOUTH:
			return Player.Wind.WEST;
		case WEST:
			return Player.Wind.NORTH;
		case NORTH:
			return Player.Wind.EAST;
		}
		return null;
	}

	private Player.Wind nextPrevailingWind(Player.Wind wind) {
		switch (wind) {
		case EAST:
			return Player.Wind.NORTH;
		case SOUTH:
			return Player.Wind.EAST;
		case WEST:
			return Player.Wind.SOUTH;
		case NORTH:
			return Player.Wind.WEST;
		}
		return null;
	}

	private boolean doesWindMatchSeason(int season, Player.Wind wind) {
		switch (season) {
		case 0:
		case 4:
			if (wind.equals(Player.Wind.EAST))
				return true;
			break;
		case 1:
		case 5:
			if (wind.equals(Player.Wind.NORTH))
				return true;
			break;
		case 2:
		case 6:
			if (wind.equals(Player.Wind.WEST))
				return true;
			break;
		case 3:
		case 7:
			if (wind.equals(Player.Wind.SOUTH))
				return true;
			break;
		}
		return false;
	}

	private String nthNumberToString(int n) {
		switch (n) {
		case 1:
			return "first";
		case 2:
			return "second";
		case 3:
			return "third";
		case 4:
			return "fourth";
		default:
			return n + "-th";
		}
	}

	private int getTabIcon(int playerNumber) {
		if (playerNumber == currentEastPlayer)
			return R.drawable.ic_tab_east;
		else if (playerNumber == (currentEastPlayer + 1) % 4)
			return R.drawable.ic_tab_north;
		else if (playerNumber == (currentEastPlayer + 2) % 4)
			return R.drawable.ic_tab_west;
		else if (playerNumber == (currentEastPlayer + 3) % 4)
			return R.drawable.ic_tab_south;
		return 0;
	}

	private int getWindIcon(Player.Wind wind) {
		switch (wind) {
		case EAST:
			return R.drawable.ic_tab_east_light;
		case NORTH:
			return R.drawable.ic_tab_north_light;
		case WEST:
			return R.drawable.ic_tab_west_light;
		case SOUTH:
			return R.drawable.ic_tab_south_light;
		default:
			return 0;
		}
	}
}